package com.zmn.brs.services.impl;

import com.zmn.brs.factory.ParseFunctionFactory;
import com.zmn.brs.services.interfaces.IFunctionService;
import com.zmn.brs.services.interfaces.IParseFunction;

/**
 * 类描述：功能服务默认实现
 *
 * @author xujie
 * @since 2021/03/12 14:19
 */
public class DefaultFunctionServiceImpl implements IFunctionService {

    private final ParseFunctionFactory parseFunctionFactory;

    public DefaultFunctionServiceImpl(ParseFunctionFactory parseFunctionFactory) {

        this.parseFunctionFactory = parseFunctionFactory;
    }

    @Override
    public String apply(String functionName, String value) {

        IParseFunction function = parseFunctionFactory.getFunction(functionName);
        if (function == null) {
            return value;
        }
        return function.apply(value);
    }

}
